﻿
"use strict";
angular.module('app.project').controller('MyAllProjectCtrl', function ($scope,$http,$rootScope, $stateParams,$cookieStore) {
    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 100,
        pagesLength: 5,
        totalItems: 20,
        perPageOptions: [10, 20, 30, 40, 50],
        plan: 0,
        onChange: function () {
        }
    };
    $scope.userid = $cookieStore.get('userid');
    $scope.fid = $cookieStore.get('userinfo').fid;
    $scope.purview = false;
    if($scope.fid !== "0" && $scope.fid !== "1"){
        $scope.purview = true;
    }
    if ($scope.fid == 1) {
        $scope.fid = $scope.userid;
    }
    // 创建项目
    $scope.createProject = function () {
        window.location.href = '#/add_newProject';
    };
    var getData = function(){
        var page_obj = {
            page:$scope.paginationConf.currentPage,
            rows:$scope.paginationConf.itemsPerPage
        };
        //获得项目数据
        $http.post(baseurl+'/list/select/project',page_obj).then(function(res){
            // console.log(res.data);
            if (res.data.ret == 1) {
                $scope.projects = res.data.rows;
                $scope.paginationConf.totalItems = res.data.records;
            }          
        })
    };
    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage',getData);
    $scope.tomypro = function(proid){//没用
        $cookieStore.put('project_id',proid);
    };
    // 项目编辑
    $scope.Edit_pro = function(id){
        window.location.href = "#/add_newProject?pro_id="+id;//编辑项目
    };


    $scope.del_granary = function(id){
        $scope.deleteid = id;
        $("#del_granary").modal('show');
    };

    $scope.sure_del = function(){
        $("#del_granary").modal('hide');
        $http.delete(baseurl+'/data/project?id=='+$scope.deleteid).then(function(res){
            if (res.data.ret == 1) {
                $("#del_granary").modal('hide');
                new Notify("success","删除成功");
                getData();
            }else if (res.data.ret != -4){
                new Notify("fail","删除失败");
            }
        });
    }
});